def get_amat(hit_time, miss_rate, miss_penalty):
    return hit_time + (miss_rate * miss_penalty)


def get_miss_penalty(hit_time, miss_rate, miss_penalty):
    """Same calculation as amat, except it calculates the next L cache.
    So the miss_penalty for L1 is the AMAT for L2.

    """
    miss_penalty = get_amat(hit_time, miss_rate, miss_penalty)
    return miss_penalty


def get_miss_rate(misses_L1, misses_L2):
    """Misses per memory references. Specific case here for L2."""
    if misses_L1 < 1:
        return 0
    return misses_L2 / misses_L1
